﻿''' <summary>
''' The module that contains functions that implememt My.Computer.FileSystem from Microsoft.VisualBasic.dll
''' </summary>
''' <remarks></remarks>
Module FileSys

#Region "File System"
    'Methods etc. regarding the file system
    'WriteAllText - with params stdalone -done
    'ReadAllText - with paramss assignment -done
    'CreateDirectory - with param  stdalone -done
    'DirectoryExists() - with param assigment
    'All Special Dirs as inline expressions assignment :-
    'MyDocuments
    'Desktop
    'MyPictures ... etc.
    'SaveFile/LoadFile for txt and rtf files
    'vbCr,vbLf and vbCrLf chars for use in strinf + files
#End Region

    ''' <summary>
    ''' Processes the request to see what function of the FileSystem is needed.
    ''' </summary>
    ''' <param name="MetCall"></param>
    ''' <remarks></remarks>
    Sub ProcessFS(ByVal MetCall As String)
        Dim metsplit As String() = MetCall.Split(New [Char]() {"("c, ")"c})

        If metsplit(0) = "WriteAllText" Then
            WriteAll(metsplit(1))
        ElseIf metsplit(0) = "CreateDirectory" Then
            CDir(metsplit(1))
        End If

    End Sub

    ''' <summary>
    ''' Implement the FileSystem.WriteAllText function. Writes text to a file.
    ''' </summary>
    ''' <param name="params">The paramaters needed to write to a file seperated by a comma.</param>
    ''' <remarks></remarks>
    Sub WriteAll(ByVal params As String)
        Dim paramsplit As String() = params.Split(New [Char]() {","c})

        Dim Dest As String = Statements.StmtsGetVal(paramsplit(0).Trim())
        Dim text As String = Statements.StmtsGetVal(paramsplit(1).Trim())
        Dim append As Boolean = CBool(Statements.StmtsGetVal(paramsplit(2).Trim()))

        My.Computer.FileSystem.WriteAllText(Dest, text, append)
    End Sub

    ''' <summary>
    ''' Creates a directory using FileSystem.CreateDirectory
    ''' </summary>
    ''' <param name="add"></param>
    ''' <remarks></remarks>
    Sub CDir(ByVal add As String)
        Dim address = Statements.StmtsGetVal(add.Trim())
        My.Computer.FileSystem.CreateDirectory(address)
    End Sub

End Module
